package by.yativem.commons.task;

import org.apache.log4j.Logger;

import by.yativem.commons.task.AbstractManagedTask.TaskStatus;

public abstract class AbstractTaskCoomand<T extends AbstractManagedTask> {
/*
	public static final class ContinueTaskCommand extends
			AbstractTaskCoomand<AbstractManagedTask> {
		
		private final Logger log = Logger.getLogger(ContinueTaskCommand.class);

		@Override
		protected final void setTask(AbstractManagedTask task) {
			try {
				task.taskStatus = TaskStatus.RUNNING;
				task.locker.notifyAll();
			} catch (Exception e) {
				log.error("", e);
			}
			// super.setTask(task);
		}

		@Override
		public void excequte() {
			// do nothinck
		}

	}
*/
	/*
	 * Represent task instance to get access to the task data from command.
	 */
	protected T task;

	protected T getTask() {
		return task;
	}

	protected void setTask(T task) {
		this.task = task;
	}

	public abstract void excequte();

	public static AbstractTaskCoomand<AbstractManagedTask> getPauseCommand() {
		return new AbstractTaskCoomand<AbstractManagedTask>() {
			private final Logger log = Logger
					.getLogger(AbstractTaskCoomand.class);

			@Override
			public void excequte() {
				try {
					task.locker.wait();
					task.taskStatus = TaskStatus.PAUSED;
				} catch (InterruptedException e) {
					log.error("", e);
				}
			}
		};
	}

	public static AbstractTaskCoomand<AbstractManagedTask> getCancelCommand(){
		return new AbstractTaskCoomand<AbstractManagedTask>() {		
			@Override
			public void excequte() {							
					task.taskStatus = TaskStatus.CANCELED;
			}
		};
		
	}

	
}
